package splab.ufcg.edu.br.trace.query.entities;

import java.io.Serializable;
import java.util.LinkedList;
import java.util.List;

public class QueryResultNode implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = -7474534539038397467L;

	private QueryExpression expression;

	private QueryResultNode nextExpression;
	
	private QueryResultNode innerParenthesisExpression;

	private boolean parenthesis;



	public QueryResultNode() {
		nextExpression = null;
		parenthesis = false;
	}

	// normalExpression expression from compiler
	public QueryResultNode(QueryExpression expression,
			QueryResultNode nextExpression) {
		this();
		this.expression = expression;
		this.nextExpression = nextExpression;
	}

	// ParenthesisExpression expression from compiler
	public QueryResultNode(QueryExpression expression,
			QueryResultNode nextExpression, boolean parenthesis) {
		this();
		this.parenthesis = parenthesis;
		this.expression = expression;
		this.nextExpression = nextExpression;
	}

	// appendExpression
	public QueryResultNode(QueryOperatorEnum operator,
			QueryResultNode nextExpression) {
		this();
		QueryExpression expression = new QueryExpression(operator);
		this.expression = expression;
		this.nextExpression = nextExpression;
	}

	public QueryResultNode(QueryExpression expression,
			QueryExpression nextExpression) {

		this.expression = expression;

		QueryResultNode nextNode = new QueryResultNode();
		nextNode.setExpression(nextExpression);
		this.nextExpression = nextNode;
	}
	
	
	


	


	


	public QueryResultNode getInnerParenthesisExpression() {
		return innerParenthesisExpression;
	}

	public void setInnerParenthesisExpression(
			QueryResultNode innerParenthesisExpression) {
		this.innerParenthesisExpression = innerParenthesisExpression;
	}

	public QueryResultNode(QueryResultNode appendInner,
			QueryResultNode appendOuter, boolean parenthesis) {
		
		this.expression = null;
		this.parenthesis = parenthesis;

		this.innerParenthesisExpression = appendInner;
		this.nextExpression = appendOuter;

		
		
	}

	public QueryExpression getExpression() {
		return expression;
	}

	public void setExpression(QueryExpression expression) {
		this.expression = expression;
	}

	public QueryResultNode getNextExpression() {
		return nextExpression;
	}

	public void setNextExpression(QueryResultNode nextExpression) {
		this.nextExpression = nextExpression;
	}

	public boolean isParenthesis() {
		return parenthesis;
	}

	public void setParenthesis(boolean parenthesis) {
		this.parenthesis = parenthesis;
	}
	
	




	@Override
	public String toString() {
		StringBuilder str = new StringBuilder();

		if (this.parenthesis) {
			str.append(" ( ");
		}

		if (this.expression != null) {
			str.append(this.expression.toString());
		}

		if (this.innerParenthesisExpression != null) {
			str.append(" ");
			str.append(this.innerParenthesisExpression.toString());
		}
		

		if (this.parenthesis) {
			str.append(" ) ");
		}

		if (nextExpression != null) {
			str.append(nextExpression.toString());
		}
		return str.toString();
	}
	
	
}
